package com.zk.mockito.cases;

import org.junit.Test;

import java.util.Arrays;

import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class Case011_StubbingWithCallbacks {

    @Test
    public void testStubbingWithCallbacks() {
        Mocked mock = mock(Mocked.class);
        when(mock.someMethod(anyString())).thenAnswer((invocation) -> {
            Object[] args = invocation.getArguments();
            Object mock1 = invocation.getMock();
            System.out.println(mock1.toString());
            return "called with arguments: " + Arrays.toString(args);
        });

        //Following prints "called with arguments: [foo]"
        System.out.println(mock.someMethod("foo"));
    }
}
